// 多门店查询
const basePage = require('../../common/BasePage')
const baseList = require('../../common/BaseList')
Page({
  behaviors: [basePage, baseList],

  /**
   * 页面的初始数据
   */
  data: {
    reqUrl: "/v1/goods/goods-info/find",
    reqData: {
      keyword: "",
      latitude: "",
      longitude: ""
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {


  },

  onReachBottom: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let globalData = getApp().globalData;
    this.data.reqData.latitude = globalData.latitude;
    this.data.reqData.longitude = globalData.longitude
  },
  search_click(e) {
    // console.log("search_click", e);

    this.setData({
      "reqData.keyword": e.detail.value
    })
    this.data.current_page = 0;
    this.setData({
      itemArr: []
    })
    this.req_items()
  },
  store_click(e) {
    // console.log("store_click", e);
    let store = {
      ...e.currentTarget.dataset.item
    };
    store.sid = store.storeSid;
    wx.setStorageSync('store', store);
    wx.navigateTo({
      url: '/pages/goods/search/index?storeSid=' + store.storeSid,
    })
  },
  goods_click(e) {
    const dataset = e.currentTarget.dataset;
    wx.setStorageSync('store', dataset.item);
    wx.setStorageSync('goods', dataset.goods);
    wx.navigateTo({
      url: '/pages/goods/search/index?storeSid=' + dataset.item.storeSid + "&firstLevelSid=" + dataset.goods.firstLevelSid,
    })
  },
  init_val(val, index, arr) {
    val.goodsInfos.map(goods => {
      goods.thumb = this.get_imgUrl(goods.imgUrl)
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },




})